package com.onec.service.api.exception;

import com.onec.service.api.dto.response.BaseResponse;
import com.onec.service.api.enums.ResultCodeEnum;
import org.slf4j.Logger;

/**
 * 异常数据处理
 *
 * @author ONEC
 * @date 2019-04-16
 */
public class ExceptionHelper {
    public static BaseResponse handlerException(Logger logger, Exception e) {
        Integer code = ResultCodeEnum.SERVER_ERROR.getCode();
        String message = ResultCodeEnum.SERVER_ERROR.getMessage();
        if (e instanceof BaseException) {
            code = ((BaseException) e).getCode();
            message = e.getMessage();
        }
        BaseResponse baseRespDto = new BaseResponse(code, message);
        logger.error("服务请求错误：code:{},msg:{}", code, message);
        return baseRespDto;
    }
}
